package com.bee.gateway.mapper;

import com.bee.gateway.common.domain.IgnoreAuthDO;
import com.bee.gateway.common.vo.IgnoreAuthQueryVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Damin.yang
 * @date 2019/07/27 22:58
 */
@Mapper
public interface IgnoreAuthMapper {

    String COLUMN = "id, service_id, uri, `desc`, status, " +
            "create_time, creator, update_time, updator, delete_time";

    /**
     * 插入
     * @param ignoreAuthDO
     * @return
     */
    @Insert("insert into ignore_auth(service_id, uri, desc, create_time, creator, update_time, updator)" +
            " values(#{serviceId}, #{uri}, #{desc}, now(), #{creator}, now(), #{updator})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(IgnoreAuthDO ignoreAuthDO);

    /**
     * 删除
     * @param id
     */
    @Update("update ignore_auth set status='N' where id=#{id}")
    void delete(long id);

    /**
     * 更新
     * @param ignoreAuthDO
     */
    @Update("update ignore_auth set service_id=#{serviceId},uri=#{uri},desc=#{desc},updator=#{updator},update_time=now()" +
            " where id=#{id}")
    void update(IgnoreAuthDO ignoreAuthDO);

    /**
     * 查询一条
     * @param id
     * @return
     */
    @Select("select " + COLUMN + " from ignore_auth where id=#{id} and status='Y'")
    IgnoreAuthDO get(long id);

    /**
     * 根据条件查询列表
     * @param queryVO
     * @return
     */
    @Select("<script>" +
            "select " + COLUMN +
            " from ignore_auth" +
            " where 1 = 1" +
            "<if test='status != null'> and status = #{status} </if>" +
            "<if test='uri != null'> and uri = #{uri} </if>" +
            "<if test='createdTimeStart != null'> and <![CDATA[created_time > #{createdTimeStart}]]> </if>" +
            "<if test='createdTimeEnd != null'> and <![CDATA[created_time < #{createdTimeEnd}]]> </if>" +
            "</script>")
    List<IgnoreAuthDO> query(IgnoreAuthQueryVO queryVO);
}
